package com.shf.dynamodb;

import java.util.HashMap;

import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import com.amazonaws.services.dynamodbv2.model.GetItemRequest;
import com.amazonaws.services.dynamodbv2.model.GetItemResult;
import com.shf.dynamodb.util.DynamoDBClientUtil;

/**
 * 低级别接口
 * @author songhaifeng
 *
 */
public class LowLevelDemo {
	
	public static void main(String[] args) {
		AmazonDynamoDBClient client=DynamoDBClientUtil.getDynamoclient();

		HashMap<String, AttributeValue> key = new HashMap<String, AttributeValue>();
		key.put("Artist", new AttributeValue().withS("No One You Know"));
		key.put("SongTitle", new AttributeValue().withS("Call Me Today"));

		GetItemRequest request = new GetItemRequest().withTableName("Music").withKey(key);

		try {
			GetItemResult result = client.getItem(request);
			if (result != null) {
				AttributeValue year = result.getItem().get("Year");
				System.out.println("The song was released in " + year.getN());
			} else {
				System.out.println("No matching song was found");
			}
		} catch (Exception e) {
			System.err.println("Unable to retrieve data: ");
			System.err.println(e.getMessage());
			e.printStackTrace();
		}finally {
			client.shutdown();
		}
	}
	
}
